package com.aaa.web.controller.employeecontroller;

import com.aaa.entity.BackRole;
import com.aaa.entity.Per;
import com.aaa.web.commons.EmpQuery;
import com.aaa.entity.Employee;
import com.aaa.web.commons.Result;
import com.aaa.web.service.iemployeeservice.IEmployeeService;
import com.aaa.web.service.iemployeeservice.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    /**
     * 员工管理页面
     */
    @RequestMapping("/getRolePage")
    public String getRolePage(){
        return "views/webhtml/employee/role-list";
    }

    /**
     * 获取所有员工
     * @param query
     * @return
     */
    @RequestMapping("/getRole")
    @ResponseBody
    public Map getAllRole(EmpQuery query) {
        Map m = roleService.getAllRole(query);
        return m;
    }

    /**
     * 获取某个员工信息
     * @param telephone
     * @return
     */
    @RequestMapping("/getRoleById")
    @ResponseBody
    public Map getRoleById(String telephone){
        Map map = roleService.getRoleById(telephone);
        return map;
    }

    /**
     * 获取该角色所有的权限
     * @param id
     * @return
     */
    @RequestMapping("/getRolePer")
    @ResponseBody
    public List<Per> getRolePer(Integer id) {
        List<Per> m = roleService.getRolePer(id);
        return m;
    }

    /**
     * 编辑该角色的信息和权限
     * @param array
     * @param role
     * @return
     */
    @RequestMapping("/updatePer")
    @ResponseBody
    public Result updatePer(int[] array, BackRole role) {
        Result result = roleService.updatePer(array,role);
        return result;
    }

    /**
     * 禁用某个角色
     * @param role
     * @return
     */
    @RequestMapping("/updateRoleState")
    @ResponseBody
    public Result updateRoleState(BackRole role) {
        Result result = roleService.updateRoleState(role);
        return result;
    }

    /**
     * 禁用某个角色
     * @param id
     * @return
     */
    @RequestMapping("/deleteRole")
    @ResponseBody
    public Result deleteRole(Integer id) {
        Result result = roleService.deleteRole(id);
        return result;
    }

    /**
     * 添加角色
     * @param role
     * @return
     */
    @RequestMapping("/addRole")
    @ResponseBody
    public Result addRole(BackRole role) {
        Result result = roleService.addRole(role);
        return result;
    }
}
